#pragma once
#include"hash_table.hpp"



template<class K, class V, class Hash = hashfunc<K>>
class my_unordered_map {
public:
	typedef pair<const K, V> T;
	struct mapKofT {
		const K& operator()(const T& data)
		{
			return data.first;
		}
	};

	typedef typename hash_table<K, T, Hash, mapKofT>::iterator iterator;
	typedef typename hash_table<K, T, Hash, mapKofT>::const_iterator const_iterator;
	typedef my_unordered_map<K, V, Hash> self;



	pair<iterator,bool> insert(const T& data)
	{
		return _hash.insert(data);
	}

	bool erase(const K& key)
	{
		return _hash.erase(key);
	}

	iterator begin()
	{
		return _hash.begin();
	}

	iterator end()
	{
		return _hash.end();
	}

	const_iterator begin()const
	{
		return _hash.begin();
	}

	const_iterator end()const
	{
		return _hash.end();
	}

	V& operator [](const K& key)
	{
		return insert(make_pair(key,V())).first->second;
	}

private:
	hash_table<K, T, Hash, mapKofT> _hash;
};


void testnuordered_map()
{
	my_unordered_map<string, string> um;
	um.insert(make_pair("hello", ""));
	um.insert(make_pair("left", ""));
	um.insert(make_pair("right", ""));
	um.insert(make_pair("yes", ""));

	auto it = um.begin();
	while (it != um.end())
	{
		//it->first = "100";
		cout << it->first << " ";
		++it;
	}
	cout << endl;
}

void testnuordered_map1()
{
	my_unordered_map<string, string> um;
	um.insert(make_pair("hello", ""));
	um.insert(make_pair("left", ""));
	um.insert(make_pair("right", ""));
	um.insert(make_pair("yes", ""));

	um["hello"] = "add";

	auto it = um.begin();
	while (it != um.end())
	{
		//it->first = "100";
		cout << it->second<< " ";
		++it;
	}
	cout << endl;
}